<?php
/**
 * Created by JetBrains PhpStorm.
 * User: adilet
 * Date: 14.08.13
 * Time: 14:01
 * To change this template use File | Settings | File Templates.
 */

class Tourism_Model_DbTable_Cities extends Engine_Db_Table
{
  protected $_rowClass = "Tourism_Model_City";

  public function getCity($city_id)
  {
    return $this->fetchRow(
      $this->select()
        ->where('city_id=?', $city_id)
        ->limit(1)
    );
  }
  public function getCities($params = array())
  {
    $select = $this->select();
    return $this->fetchAll($select);
  }

  public function getCitiesPaginator($params = array())
  {
    $select = $this->select();
    $page = isset($params['page']) && !empty($params['page']) ? $params['page'] : 0;
    if (!empty($params['title'])) {
      $select->where('title LIKE ?', '%' . $params['title'] . '%');
    }
    $paginator = Zend_Paginator::factory($select);
    $paginator->setItemCountPerPage(10);
    $paginator->setCurrentPageNumber($page);
    return $paginator;
  }

}